<style scoped lang="scss">
.materialDtl_with_secItemCom {
    font-size: 13px;
}
.secitem-swipe-cell{
     &:last-child{
          margin-bottom: 2px!important;

     }

}
</style>
<template>
    <div class="permitbutton" style="display: none">
<!--        props_secondaryList: {{ $props.props_secondaryList }}-->
        p[materialState:{{$props.props_develMaterialCheck?.materialState}}
    </div>
    <div class="materialDtl_with_secItemCom"
         style="padding: 5px;border-radius: 5px;box-sizing: border-box;border: 1px solid #ddd">
        <div
                desc="header">
            <div class="flex"
                 style="display: flex;
                 justify-content: space-between;
                 align-items: center;
                 width: 100%;padding-bottom:10px;border-bottom:1px solid #ddd;">
                <div>

                    <van-tag type="danger" v-if="$props?.props_develMaterialItem?.returnState == 5"
                             style="margin-right:5px;">驳
                    </van-tag>
                    <van-tag type="danger" size="mini" v-if="$props?.props_develMaterialItem?.priorityGrade == 2"
                             style="margin-right:5px;">急
                    </van-tag>
                    <van-tag plain type='primary' size="mini" v-if="$props?.props_develMaterialItem?.develMethod"
                             style="margin-right:5px;">{{
                        getDevelMethod($props?.props_develMaterialItem?.develMethod)
                        }}
                    </van-tag>
                    <dic-tag :value="$props?.props_develMaterialItem?.develType"
                             v-if="$props?.props_develMaterialItem?.develType"
                             style="margin-right:5px;"
                             :code="dic.MesDevelMaterial.mesDevelMaterial_devel_type"></dic-tag>
                    <dic-tag :value="$props?.props_develMaterialItem?.revisionType"
                             v-if="$props?.props_develMaterialItem?.revisionType"
                             plain
                             :code="dic.MesDevelMaterial.mesDevelMaterial_revision_type"></dic-tag>
                    <small style="padding-left: 5px"
                          class="fontsizetitle blod">{{ $props?.props_develMaterialItem?.proCode }}</small>
                  <small style="padding-left: 5px"
                        class="fontsizetitle blod">{{ $props?.props_develMaterialItem?.develNo }}</small>
                </div>
                <!--         <span style="margin-left:5px;"
                               class="fontsizetitle blod"> {{ $props.item?.productNew?.name }}</span>-->
                <div>
                    <small style="padding-right: 5px;">{{
                        datemmddhhmm($props?.props_develMaterialItem?.applyTime)
                        }}</small>
                    <small>{{ $props?.props_develMaterialItem?.addUser }}</small>
                </div>
            </div>
        </div>

        <section class="body" style="padding-top: 10px">
            <template v-if="1==1">
                <template v-for="(secItem,secIndex) in  ($props.props_secondaryList||[])"
                          :key="secIndex"
                >
                    <van-swipe-cell
                          class="secitem-swipe-cell"
                            style="font-size: 16px;margin-bottom: 15px;border-bottom: 1px  solid #ddd;padding-bottom: 10px;;">
                        <section style="display: flex;">
                            <div style="margin-right: 5px;">
                                <input type="checkbox" :class="`checkbox_sec checkbox_sec_${secItem?.id}`"
                                         v-if="$props.props_show_checkbox"
                                       :data-secid="secItem?.id"
                                       :data-develdtlid="$props.props_develMaterialItemDtl?.id"
                                       :data-checkid="$props.props_develMaterialCheck?.id"
                                       desc-disabled="物料收货之后 才能工艺收货"
                                       :disabled="($props.props_develMaterialCheck?.materialState!=25)"
                                />
                            </div>
                            <div style="position: relative;flex:1;">
                                <div v-if="$props.props_show_close2" style="position: absolute;top: -2px;right:0px;z-index:998">
                                    <svg-icon
                                        @click.native="()=>triggerSecDelete(secItem,secIndex)"
                                        icon-class="close-circle" style="font-size: 18px;color: red;"></svg-icon>
                                </div>
                                <receiving_secCom
                                                  :props_edit="$props.props_edit"
                                                  :props_activeName="$props.props_activeName"
                                    :props_materialReceivingDtl="secItem?.materialReceivingDtl"
                                                  @updateMoney="$emit('updateMoney')"
                                                  :secItem="secItem"></receiving_secCom>
                            </div>

                        </section>
                        <template #right>
                            <van-button square type="danger" text="删除" size="small" style="height: 20px"
                                        @click="()=>deleteOneSec(secItem,secIndex)"
                                        desc-disabled="物料收货之后 才能工艺收货"
                                        v-if="computed_show_delete(secItem)"
                            />
                        </template>
                    </van-swipe-cell>
                </template>
            </template>
        </section>

        <div style="margin-top: 5px;margin-bottom: 2px;">
            <div style="display: none" class="permitbutton">
                {{ $props.props_develMaterialItemDtl }}
            </div>

            <label for="">
                <span>供应商：</span>
                <span>{{ $props?.props_develMaterialItemDtl?.supplierName }}
         <span>({{ $props?.props_develMaterialItemDtl?.supplierProCode }})</span>
       </span>
            </label>

        </div>
    </div>
</template>
<script>
import receiving_secCom from './receiving_sec.vue'

function getDevelMethod(mmm) {
    var map = {
        1: '本',
        2: '外',
    };
    return map[mmm];
}

import * as dic from '@/utils/dic';

import * as matertailDevApi from '@/api/material_dev';


import DicTag from '@/components/DicTag/dic-tag.vue';
import {datemmddhhmm} from '@/utils/dateUtils';
import {toFixedInt} from '@/utils';
import {alertConfirm} from '@/utils/alertUtil';

export default {
    components: {
        receiving_secCom,
        DicTag,
    },
    data() {
        return {
            getDevelMethod,
            dic,
            toFixedInt,
            datemmddhhmm,
        };
    },
    props: {
        props_edit: {
            type: [Boolean], default() {
                return false;
            },
        },
        props_show_checkbox: {
            type: [Boolean],
            default(){
                return true
            }
        },
        props_secondaryList: {
            type: [Object, Array],
        },
        props_develMaterialItemDtl: {
            type: [Object],
        },
        props_develMaterialItem: {
            type: [Object],
        },
        props_develMaterialCheck: {
            type: [Object],
        },
        props_materialReceiving: {
            type: [Object],
        },
        props_show_close: {
            type: [Boolean], default() {
                return true;
            },
        },
        props_show_close2: {
            type: [Boolean], default() {
                return false;
            },
        },
        edit: {
            type: [Boolean], default() {
                return false;
            },
        },
        props_billingType: {
            type: [String, Number],
        },
        props_materialReceivingDtl: {
            type: [Object],
        },
        props_activeName:{
          type: [String, Number],
        }
    },
    methods: {
        computed_show_delete(secItem) {
            if (/*第二种删除模式打开 第一种隐藏*/this.$props.props_show_close2) {
                return false
            }
            return secItem?.state != 25 || this.$props.props_develMaterialCheck?.state >= 3
        },
        async deleteOneSec(secItem, index) {
            await alertConfirm('确定删除二次工艺吗？');
            debugger
            if (secItem?.id) {
                var result = await matertailDevApi.delsecondbyid(secItem?.id);

                this.$props?.props_secondaryList?.splice(index, 1);
            }
        },
        async triggerSecDelete(secItem, index) {
             await alertConfirm('确定删除吗？')
            this.$props.props_secondaryList?.splice(index,1)
            this.$emit('triggerSecDelete', {secItem, index});

        },
    },


};
</script>
